feat[ServletAdapter]: Ability remove context path when get method name#11730
feat[ServletAdapter]: Ability remove context path when get method name#11730long76 wants to merge 10 commits intogrpc:masterfrom
Conversation
|
Could you please describe the problem you are trying to solve? |
I use Wildfly 24 and need use non root context( |
No.
They are not real clients, but UI tools to send arbitrary requests to server for development purposes. |
|
Yeah, there's not going to be clients that work with this. It sounds like you would get testing infrastructure running, but once you try to make real clients you're going to have problems. |
|
@ejona86 local fork works great on Wildfly 24, my patch do not break backward compatibility |
|
The server is irrelevant. We were saying the clients won't support this as gRPC doesn't support this. |
This will work with proxy. Nginx > Wildfly > GRPCServlet works. I do not see limitations for support this for GRPCServlet. |
|
@long76 Do you mean ngx_http_grpc_module ? |
😏Just try this config for nginx: P.S. i don't know it's bug or feature nginx but i glad this flexibility) |
ejona86
left a comment
There was a problem hiding this comment.
Doesn't REMOVE_CONTEXT_PATH mean that you must put the servlet under its own "folder" because it will need a wildcard for the full service/method. So where your app may be /app1, you'd then have to do something like /app1/grpc/* for the servlet so that the requested path is /app1/grpc/helloworld.Greeter/SayHello?
| * <p>Do not modify {@code req} and {@code resp} before or after calling this method. However, | ||
| * calling {@code resp.setBufferSize()} before invocation is allowed. | ||
| */ | ||
| public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { |
There was a problem hiding this comment.
Deleting this breaks compatibility. If you have to modify the helloworld example (hard-coding a string no less!), then that clearly is API-breaking.
There was a problem hiding this comment.
i agree that hard-coded string is bad but for now i dont found better solution, i need more time or you can suggest smth
There was a problem hiding this comment.
I don't follow the difficulty.
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
doPost(req.getRequestURI().substring(1), req, resp);
}| } | ||
|
|
||
| private String getMethod(HttpServletRequest req) { | ||
| Boolean removeContextPath = Boolean.parseBoolean(getInitParameter(REMOVE_CONTEXT_PATH)); |
There was a problem hiding this comment.
This shouldn't be done per-request. We should do this in init instead, right?
| } | ||
|
|
||
| private String getMethod(HttpServletRequest req) { | ||
| Boolean removeContextPath = Boolean.parseBoolean(getInitParameter(REMOVE_CONTEXT_PATH)); |
| String method = req.getRequestURI(); | ||
| if (removeContextPath) { | ||
| // remove context path used in application server | ||
| method = method.substring(req.getContextPath().length()); |
There was a problem hiding this comment.
Isn't this mostly the same as req.getPathInfo()? I wouldn't expect to need to do any string manipulation.
There was a problem hiding this comment.
no, at first I thought the same thing. only getContextPath() needed. see https://coderanch.com/t/610432/certification/getContextPath-getServletPath-getPathInfo
There was a problem hiding this comment.
I see, you are making it relative to the deployment.
in our case we create dedicated |
|
new pull #11825 |
|
@long76 Have you considered name-based virtual hosting? and then deploy this code as ROOT.war in the "mygrpc" host. |
yeah, but we need our business logic from our app. we use ejb for access data from other |
|
@long76 There is also an "enterprise" way - you could use a servlet filter. |
yeah but it doesn't work) it's was first that i try) maybe i make mistake somewhere |
|
@long76 it seems like in your gRPC servlet class in new HttpServletRequestWrapper(req) {
@Override
public String getRequestURI() {
return super.getRequestURI().replaceFirst("^/grpc", "");
}
};As your setup does not quite match the current state of gRPC- not clear if the related changes should be in the library. |
Yeah, but no) Yes my changes does not match grpc library but it's very useful for application server users and finally it's easy realize in library) |
|
@long76 you can copy |
Copy paste 😒 i better use our release with patch) |
Refs: #5066
Complex application may have many
war-s and do not allow monopolize root context path(/). Add ability to remove context path(usual it'swarname) from application server use@WebInitParamor just overridegetInitParameterfor parameterGrpcServlet.REMOVE_CONTEXT_PATHhttps://stackoverflow.com/a/42706412